package com.example.springbackfront.controller;

import com.example.springbackfront.mapper.StudentMapper;
import com.example.springbackfront.mapper.SubmitMapper;
import com.example.springbackfront.test.Student;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Length;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Slf4j
@Validated   //首先在Controller上开启接口校验
@Controller
public class ValidateController extends BaseValidate {

    @Resource
    SubmitMapper mapper;
    @ResponseBody
    @PostMapping("/submit")
    public String submit(@Length(min = 3) String username,  //使用@Length注解一步到位
                         @Length(min = 10) String password){
        System.out.println(username.substring(3));
        System.out.println(password.substring(2, 10));
        return "请求成功!";
    }

    // 校验对象
//    @ResponseBody
//    @PostMapping("/submitObject")
//    public String submitObject(Student student){   //直接使用对象接收
//        System.out.println(student.getName().substring(3));
//        System.out.println(student.getPassword().substring(2, 10));
//        return "请求成功!";
//    }
}
